package org.linlinjava.litemall.web.controller;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.web.annotation.LogAnno;
import org.linlinjava.litemall.web.annotation.LoginShop;
import org.linlinjava.litemall.web.annotation.LoginUser;
import org.linlinjava.litemall.web.service.WebCalculateSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 网络计算解决控制器
 * 下班结算控制器
 *
 * @author yliyun
 * @Author: chenyu
 * @Date: 2022/7/6 11:10
 * @Version: 1.0
 * @Description: 每日结算
 * @date 2022/09/14
 */

@RestController
@RequestMapping("/web/settlement")
@Validated
public class WebCalculateSettlementController {

    /**
     * 结算服务
     */
    @Autowired
    private WebCalculateSettlementService settlementService;

    /**
     * 现金结算
     * 记录结算金额
     *
     * @param totalCash      钱箱中金额
     * @param curDeserveCash 钱箱中应有金额
     * @param shopId         商店id
     * @param userId         用户id
     * @return {@link Object}
     */
    @PostMapping("settleCash")
    @LogAnno
    public Object settleCash(@RequestParam BigDecimal totalCash, @RequestParam  BigDecimal curDeserveCash,
                             @RequestParam String denomination,
                             @LoginShop Integer shopId,@LoginUser Integer userId){
        return settlementService.add(totalCash, curDeserveCash, shopId, userId,denomination);
    }

    /**
     * 得到原始现金
     * 结算前查看原有金额
     *
     * @param shopId 商店id
     * @return {@link Object}
     */
    @GetMapping("getOriginalCash")
    @LogAnno
    public Object getOriginalCash(@LoginShop Integer shopId){
        return ResponseUtil.ok(settlementService.getOriginalCash(shopId));
    }

    /**
     * 插入现金后打开
     *
     * @param amount 量
     * @param shopId 商店id
     * @param userId 用户id
     * @return {@link Object}
     */
    @PostMapping("insertCashAfterOpen")
    @LogAnno
    public Object insertCashAfterOpen(BigDecimal amount,@LoginShop Integer shopId,@LoginUser Integer userId){
        return settlementService.insertCashAfterOpen(amount, shopId, userId);
    }
}
